package javabasics.equilsandhashcode;
/**
 * 针对equils与hashcode来定义
 *
 *
 * */
public class EquilsDemo {

    public EquilsDemo(String obj){}

    public static void main(String[] args) {

        String obj1 = new String("obj1");
        String obj2 = obj1;
        System.out.println("equils:" + obj1.equals(obj2));
        System.out.println("equils hashcode:" + (obj1==obj2));
        System.out.println("obj1 hashcode:" + obj1.hashCode() + "    obj2 hashcode:" + obj2.hashCode());
        obj2 = new String("obj1");
        System.out.println("equils:" + obj1.equals(obj2));
        System.out.println("equils hashcode:" + (obj1==obj2));
        System.out.println("obj1 hashcode:" + obj1.hashCode() + "    obj2 hashcode:" + obj2.hashCode());

        System.out.println("******************");


        EquilsDemo wquilsDemo = new EquilsDemo("EquilsDemo1");
        EquilsDemo wquilsDemo2 = wquilsDemo;
        System.out.println("wquilsDemo:" + wquilsDemo.equals(wquilsDemo2));
        System.out.println("equils hashcode:" + (wquilsDemo==wquilsDemo2));
        System.out.println("wquilsDemo hashcode:" + wquilsDemo.hashCode() + "    wquilsDemo2 hashcode:" + wquilsDemo2.hashCode());

        System.out.println("******************");

        wquilsDemo2 = new EquilsDemo("EquilsDemo1");
        System.out.println("equils:" + wquilsDemo.equals(wquilsDemo2));
        System.out.println("equils hashcode:" + (wquilsDemo==wquilsDemo2));
        System.out.println("wquilsDemo hashcode:" + wquilsDemo.hashCode() + "    wquilsDemo2 hashcode:" + wquilsDemo2.hashCode());

    }
}
